{include file="my/header"}
<div class="container-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            {if condition="session('userclass') eq 1"}
            <span class="from-title">计算机与信息工程学院</span>
            {else /} <span class="from-title">全学院</span>
            {/if}
            <label>(所有课程)</label>

            <form class="layui-form layui-inline J-search-form" style="float: right;" action="">
                {if session('userclass') == '10' || session('userclass') == '2'}
                <div class="layui-inline">
                    <label class="layui-form-label">学院:</label>
                    <div class="layui-inline">
                        <select name="college" class="layui-input J-query-params" lay-filter="test">
                            <option value="">全部</option>
                            {volist name='college' id='college'}
                            <option value="{$college.id}">{$college.college}</option>
                            {/volist}
                        </select>
                    </div>
                </div>
                {/if}

                <div class="layui-inline">
                    <label class="layui-form-label">学期:</label>
                    <div class="layui-inline">
                        <select name="term" class="layui-input J-query-params" lay-filter="test">
                            <option value="">全部</option>
                            <option value="1">1</option>
                            <option value="2">2</option>
                        </select>
                    </div>
                </div>
            </form>
            <!-- 表格数据查询块 -->
            <!-- <div class="table-query">
                <form class="layui-form layui-inline J-search-form" action="">
                    <div class="layui-inline">
                        <label class="layui-form-label">搜索ID：</label>
                        <div class="layui-inline">
                            <input class="layui-input J-query-params" name="id" autocomplete="off" placeholder="请输入id" />
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">课程:</label>
                        <div class="layui-inline">
                            <input class="layui-input J-query-params" name="coursename" autocomplete="off" placeholder="请输入课程" />
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">考试任务:</label>
                        <div class="layui-inline">
                            <input class="layui-input J-query-params" name="name" autocomplete="off" placeholder="请输入内容" />
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">审核状态:</label>
                        <div class="layui-inline">
                            <select name="check" class="layui-input J-query-params">
                                <option value="" selected>请选择审核状态</option>
                                <option value="0">未审核</option>
                                <option value="1">已通过</option>
                                <option value="2">未通过</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">发布时间:</label>
                        <div class="layui-inline">
                            <input type="text" class="layui-input J-query-params J-date" name="create_time" placeholder="yyyy-MM-dd" />
                        </div>
                    </div>
                </form>
                <button class="layui-btn J-search" data-type="reload">搜索</button>
                <button class="layui-btn J-reload">重置</button>
            </div> -->
            <!-- 表格 -->
            <table class="layui-hide" id="testTable" lay-filter="tableOption"></table>
            <!-- 表格工具 -->
            <script type="text/html" id="toolbarDemo">
                <!-- <div class="layui-btn-container">
                    <button class="layui-btn layui-btn-sm" lay-event="add">添加课程</button>
                    <button class="layui-btn layui-btn-sm" lay-event="batchdel">批量删除</button>
                    <button class="layui-btn layui-btn-sm test" lay-data="{url: '/b/', accept: 'file'}" lay-event="import">批量导入课程</button>
                    <button class="layui-btn layui-btn-sm" lay-event="orderCourse">课程安排</button>
                </div> -->
            </script>

            <script type="text/html" id="barDemo">
                <a href="{:url('index/score/scoreStatsCheck')}?id={{ d.id }}&kechengid={{ d.kechengid }}&banjiid={{ d.banjiid }}" class="layui-btn layui-btn-xs">班级成绩审核</a>
                <!-- <a class="layui-btn layui-btn-xs" lay-event="input">录入成绩</a> -->
                <!--
                <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a> -->
            </script>
        </div>

        <!-- 退出模板框 -->
        <!-- 课程安排 -->
        <div class="margin-top30 J-temple is-hidden">
            <form class="layui-form layui-fluid J-manage-course" lay-filter="formTest">
                <input type="hidden" class="form-control" id="id" name="id" value="" placeholder="请输入内容" />
                <input type="hidden" class="form-control" id="schoolid" name="schoolid" value="99" placeholder="请输入内容" />
                <div class="layui-form-item">
                    <label class="layui-form-label">学期</label>
                    <div class="layui-input-block">
                        <input type="text" class="layui-input" name="term" placeholder="请输入内容" />
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">课程</label>
                    <div class="layui-input-block">
                        <select name="kechengid">
                            {volist name='kechengdata' id='kechengdata'}
                            <option value="{$kechengdata.id}">{$kechengdata.coursename}</option>
                            {/volist}
                        </select>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">周次</label>
                    <div class="layui-input-block">
                        <input type="text" class="layui-input" name="weekno" placeholder="请输入内容" />
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">星期</label>
                    <div class="layui-input-block">
                        <input type="text" class="layui-input" name="week" placeholder="请输入内容" />
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">节次</label>

                    <div class="layui-input-block">
                        <input type="text" class="layui-input" name="section" placeholder="请输入内容" />
                    </div>
                </div>

                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">班级</label>
                    <div class="layui-input-block">
                        <input type="text" class="layui-input" name="banjiid" placeholder="请输入内容" />
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">人数</label>
                    <div class="layui-input-block">
                        <input class="layui-input" name="number" autocomplete="off" placeholder="请输入内容" />
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">上课教师</label>
                    <div class="layui-input-block">
                        <select name="teacherid" id="teacherid">
                            {volist name='teacherinfodata' id='teacherinfodata'}
                            <option value="{$teacherinfodata.teacherid}">{$teacherinfodata.teachername}</option>
                            {/volist}
                        </select>
                    </div>
                </div>

                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">备注</label>
                    <div class="layui-input-block">
                        <textarea name="memo" placeholder="请输入内容" class="layui-textarea"></textarea>
                    </div>
                </div>
            </form>
        </div>
        <!-- 添加课程 -->
        <div class="margin-top30 J-add-course is-hidden">
            <form class="layui-form layui-fluid J-add-form" lay-filter="formTest">
                <input type="hidden" class="form-control" id="id" name="id" value="" placeholder="请输入内容" />
                <input type="hidden" class="form-control" id="schoolid" name="schoolid" value="99" placeholder="请输入内容" />
                <div class="layui-form-item">
                    <label class="layui-form-label">课程名称</label>
                    <div class="layui-input-block">
                        <input class="layui-input" name="coursename" autocomplete="off" placeholder="请输入内容" />
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

<script>
    $(function () {
        initClass('courselist');
        // initTable();
        layuiDate('.J-date');
        initLayui(initTable);

    });

    function initTable() {
        var table;
        // 请求路径
        var requireUrl = {
            add: "{:url('score/course_add')}",
            edit: "{:url('score/manage_course_edit')}",
            remove: "{:url('score/course_remove')}",
            list: "{:url('score/get_course_list')}",
            manage: "{:url('score/manage_course')}",
            input: "{{:url('score/result_input')}}",
        };

        layui.use('table', function () {
            table = layui.table;
            table.render({
                elem: '#testTable',
                url: requireUrl.list,
                toolbar: '#toolbarDemo',
                title: '课程管理',
                totalRow: false,
                cols: [
                    [
                        {
                            type: 'checkbox',
                            fixed: 'left',
                            align: 'center',
                            minWidth: '100',
                        },
                        {
                            field: 'id',
                            title: 'ID',
                            align: 'center',
                            minWidth: '100',
                        },
                        {
                            field: 'term',
                            title: '学期',
                            align: 'center',
                            minWidth: '100',
                        },
                        {
                            field: 'coursename',
                            title: '课程',
                            align: 'center',
                            minWidth: '100',
                        },
                        {
                            field: 'weekno',
                            title: '周次',
                            align: 'center',
                            minWidth: '100',
                        },
                        {
                            field: 'week',
                            title: '星期',
                            align: 'center',
                            minWidth: '100',
                        },
                        {
                            field: 'section',
                            title: '节次',
                            align: 'center',
                            minWidth: '100',
                        },
                        {
                            field: 'class_name',
                            title: '班级',
                            align: 'center',
                            minWidth: '100',
                            // templet: function (d) {
                            //     var result;
                            //     if (d.result == 0) result = '<span class="green">正常</span>';
                            //     if (d.result == 1) result = '<span class="red">缺考</span>';
                            //     if (d.result == 2) result = '<span class="red">作弊</span>';
                            //     return result;
                            // },
                        },
                        {
                            field: 'number',
                            title: '人数',
                            align: 'center',
                            minWidth: '100',
                        },
                        {
                            field: 'teachername',
                            title: '授课老师',
                            align: 'center',
                            minWidth: '100',
                        },
                        {
                            field: 'room',
                            title: '上课教室',
                            align: 'center',
                            minWidth: '100',
                            // templet: (d) => {
                            //   return d.check1 == 0 ? "未审核" : "已审核";
                            // },
                        },
                        {
                            field: 'check1',
                            title: '学院审核',
                            align: 'center',
                            minWidth: '100',
                            templet: function (d) {
                                var result;
                                if (d.check1 == 0) result = '<span class="">未审核</span>';
                                if (d.check1 == 1) result = '<span class="green">通过</span>';
                                if (d.check1 == 2) result = '<span class="red">不通过</span>';
                                return result;
                                return result;
                            },
                        },
                        {
                            field: 'check2',
                            title: '教务处审核',
                            align: 'center',
                            minWidth: '100',
                            templet: function (d) {
                                var result;
                                if (d.check2 == 0) result = '<span class="">未审核</span>';
                                if (d.check2 == 1) result = '<span class="green">通过</span>';
                                if (d.check2 == 2) result = '<span class="red">不通过</span>';
                                return result;
                                return result;
                            },
                        },
                        {
                            field: 'input_state',
                            title: '录入状态',
                            align: 'center',
                            minWidth: '100',
                            templet: function (d) {
                                var result;
                                if (d.input_state == 0) result = '<span class="">未录入</span>';
                                if (d.input_state == 1) result = '<span class="green">已录入</span>';
                                return result;
                            },
                        },
                        {
                            field: 'memo',
                            title: '备注',
                            align: 'center',
                            minWidth: '100',
                            // templet: (d) => {
                            //   return d.check2 == 0 ? "未审核" : "已审核";
                            // },
                        },
                        // , { field: 'create_time', title: '时间', align: 'center', minWidth: '120', }
                        {
                            fixed: 'right',
                            title: '操作',
                            toolbar: '#barDemo',
                            width: 120,
                        },
                    ],
                ],
                id: 'testReload',
                page: true,
                parseData: function (res) {
                    return {
                        code: 0,
                        msg: '',
                        count: res.length,
                        data: res,
                    };
                },
            });

            //工具栏事件
            table.on('toolbar(tableOption)', function (obj) {
                var checkStatus = table.checkStatus(obj.config.id);
                switch (obj.event) {
                    case 'add':
                        tableAdd({
                            addUrl: requireUrl.add,
                            layerTemp: $('.J-add-course'),
                            title: '添加课程',
                        });
                        break;
                    case 'batchdel':
                        // 批量删除课程
                        tableBatchDel(checkStatus, requireUrl.remove);
                        break;
                    case 'import':
                        // 批量导入课程
                        upload.render({
                            elem: '.test',
                            done: function (res, index, upload) {
                                //获取当前触发上传的元素，一般用于 elem 绑定 class 的情况，注意：此乃 layui 2.1.0 新增
                                var item = this.item;
                            },
                        });
                        break;
                    case 'orderCourse':
                        // TODO课程安排
                        var obj = {
                            addUrl: requireUrl.manage,
                            layerTemp: $('.J-temple'),
                            title: '排课程',
                        };
                        resetAll($('.J-add-form'));
                        layerOpenInit(obj.title, obj.layerTemp, function (index) {
                            var data = $('.J-manage-course').serialize();
                            data += '&create_time=' + new Date().Format('yyyy-MM-dd hh:mm:ss');
                            // return
                            ajaxRequest('post', obj.addUrl, data, function (data) {
                                var errMesage = data.msg ? data.msg : data;
                                data.code == 1 ? successTrip(data) : errorAlert(false, errMesage);
                            });
                        });
                        break;
                }
            });

            //监听行工具事件
            table.on('tool(tableOption)', function (obj) {
                var data = obj.data;
                if (obj.event === 'del') {
                    layerConfirm(requireUrl.remove, {
                        id: data.id,
                    });
                } else if (obj.event === 'edit') {
                    layerOpenInit(
                        '编辑',
                        $('.J-temple'),
                        function (index) {
                            var data = $('form').serialize();
                            ajaxRequest('post', requireUrl.edit, data, function (data) {
                                data.code == 1 ? successTrip(data) : errorAlert(false, data.msg);
                            });
                        },
                        function () {
                            ajaxRequest(
                                'get',
                                requireUrl.edit,
                                {
                                    id: data.id,
                                },
                                function (res) {
                                    form.val('formTest', res.data);
                                }
                            );
                        }
                    );
                } else if (obj.event === 'input') {
                    // ajaxRequest('get', requireUrl.input, null, function (data) {
                    //     data.code == 1 ? successTrip(data) : errorAlert(false, data.msg);
                    // });
                }
            });
        });




        // 搜索重置操作
        var active = {
            reload: function () {
                var queryParams = serializeObject($('.J-search-form'));
                //执行重载
                table.reload(
                    'testReload',
                    {
                        page: {
                            curr: 1, //重新从第 1 页开始
                        },
                        where: queryParams,
                    },
                    'data'
                );
            },
        };
        $('.J-search').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        form.on('select(test)', function (data) {
            var type = 'reload';
            active[type] ? active[type].call(this) : '';
        });

        $('.J-reload').on('click', function () {
            $('.J-query-params').val('');
            form.render('select');
            active.reload ? active.reload.call(this) : '';
        });
    }
</script>

{include file="my/footer"}